package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.MenuDao;
import com.itheima.entity.PageResult;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service(interfaceClass = MenuService.class)
@Transactional
public class MenuServiceImpl implements MenuService {
    @Autowired
    MenuDao menuDao;
    @Override
    //根据level查菜单
    public List<Menu> findByMenuLevel1(Integer level) {
        return menuDao.findByLevel(level);
    }

    //删除菜单
    public void delete(Integer id) {
        menuDao.delete(id);
    }
    //根据id查询
    public Menu findById(Integer id) {
        Menu menu = menuDao.findById(id);
        return menu;
    }
    //删除和角色的关联关系
    @Override
    public void deleteAssociation(Integer id) {
        menuDao.deleteAssociation(id);
    }

    @Override
    //查询一级菜单
    public List<Menu> findlevel1Menu() {
       return menuDao.findlevel1Menu();
    }

    @Override
    //添加菜单
    public void add(Menu menu) {
        menuDao.add(menu);
    }

    @Override
    //编辑菜单
    public void edit(Menu menu) {
        menuDao.update(menu);
    }

    //分页查询
    public PageResult pageQuery(String queryString, Integer pageSize, Integer currentPage) {
        PageHelper.startPage(currentPage,pageSize);
        Page<Menu> menus = menuDao.pageQuery(queryString);
        return new PageResult(menus.getTotal(),menus.getResult());
    }

    @Override
    //查询子菜单
    public List<Menu> findChildrenByParentId(Integer id) {
       return menuDao.findChildrenByParentId(id);
    }
}
